﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace StreetlightGames.XnaEngine
{
    public static class VectorHelper
    {
        public static Vector3 RotateX(Vector3 vector, float radians)
        {
            Matrix rotationMatrix = Matrix.CreateRotationX(radians);
            return Vector3.Transform(vector, rotationMatrix);
        }

        public static Vector3 RotateY(Vector3 vector, float radians)
        {
            Matrix rotationMatrix = Matrix.CreateRotationY(radians);
            return Vector3.Transform(vector, rotationMatrix);
        }

        public static Vector3 RotateZ(Vector3 vector, float radians)
        {
            Matrix rotationMatrix = Matrix.CreateRotationZ(radians);
            return Vector3.Transform(vector, rotationMatrix);
        }

        public static float GetDistance(Vector3 vector1, Vector3 vector2)
        {
            Vector3 delta = vector2 - vector1;
            return delta.Length();
        }

        public static Vector3 CreateVector(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return Vector3.Zero;
            }
            string[] parts = data.Split('|');
            if (parts.Length < 3)
            {
                return Vector3.Zero;
            }
            return new Vector3(Convert.ToSingle(parts[0]), Convert.ToSingle(parts[1]), Convert.ToSingle(parts[2]));
        }

        public static string ConvertVectorToString(Vector3 vector)
        {
            return string.Format("{0}|{1}|{2}", vector.X, vector.Y, vector.Z);
        }
    }
}
